Setting layers for efficient rendering

Kanzi traverses layers in the order as they are organized in the scene graph using what resembles the painter’s algorithm, meaning that if you place a background layer as the first node in the tree, pixels containing content are drawn first for the background and then again for the content layers. Which is why you can improve performance by placing the layers in the scene graph in front-to-back order.

Using layers can be very useful for some applications, but they can also be computationally heavy if used carelessly. In some cases a child layer will have to be rendered first at its own render target object, which is basically equivalent to rendering the parent layer and child layers separately. The following cases cause such behavior:

Layer render on demand

You can improve rendering performance by using Layer Render On Demand. When using Layer Render On Demand you can render layers in a more optimal order and only when rendering is required.

When you enable the Layer Render On Demand property in the Screen, Kanzi Engine renders layers one by one so that all opaque layers are rendered from front to back and then all transparent layers from back to front. If there are multiple opaque layers, this helps the performance, since GPU provides Early-Z mechanism, where progressing of fragment that has been already written can be skipped.

In many cases areas do not have to be rendered, especially if only a few layers have changed. When you use Layer Render On Demand, Kanzi Engine renders only the modified layers and layers with dependencies to modified layers. Indicator that triggers the rendering is a property change for property type that has Affect Rendering property enabled. The property is notified in several situations, for example, when attaching and detaching in scene graph.

Note that you cannot use Layer Render On Demand if the composer of one of the layers in your project has side effects on the application state. For example, when using Layer Render On Demand, a scene rendered with a render to texture composer in one viewport layer is not correctly rendered to a texture in another layer.

See the Gestures example to see an example use of Layer Render On Demand property in the Screen. To visualize the render area, in the Preview enter the Debug mode and select Overdraw visualization. Notice how only the modified layer area and the dependencies are rendered, thus improving performance and reducing battery consumption. See Gestures example.

Viewing transparent layers in your application

In Kanzi Studio you can see which layers in your applications are transparent, and thus show the content behind them.

To view transparent layers in the Preview enter the Debug mode and select Layer is transparent visualization.
The Preview highlights the transparent areas with transparent, blue stripes.

Note that by default the value of Layer Background Brush Color property of viewport layers is transparent (0, 0, 0, 0), and that the Clear Color does not affect the transparency condition directly.

Preserving the back buffer

Layer Render On Demand requires that the back buffer is preserved during the buffer swap. Preserving the back buffer is the default behavior on most devices, but some devices require that you enable it explicitly.

To enable preserving of the back buffer in kzApplicationConfigure() set:

configuration->surfaceProperties.swapBehaviorCopy = 1;

Layer Render On Demand is not compatible on devices that do not support the back buffer preservation. In such cases you can use Layer Render On Demand to render to a texture.

Triggering rendering of layer

Trigger the rendering of a layer through a dependency when it is behind a transparent layer and the transparent layer changes.

To trigger rendering of a specific layer or object, call kzuObjectNodeInvalidateRender.

Setting a layer to always be rendered

When you always want to render a layer, but cannot create any external triggers, use Layer Render Always property. For example, you can use this with a layer that contains a video.

To set a layer to always be rendered:

  1. In the Project select the layer you always want to render.
  2. In the Properties click Add Properties, add Layer Render Always property, and enable it.

Releasing the memory allocated to the framebuffer objects no longer in use

When you use a Transition Layer to transition between two layers, you can release the memory allocated to the framebuffer objects that the Transition Layer no longer uses.

To release the memory allocated to framebuffer objects no longer in use:

  1. In the Project select the Transition Layer.
  2. In the Properties click Add Properties, add the Release Inactive Render Targets property, and enable it.

See also

Rendering best practices

Partial rendering

Optimizing rendering of layouts

Setting layers for efficient rendering

Preventing overdraw with sorting filters

Rendering static content

Rendering transparent objects

Gestures example

Measuring the performance of your Kanzi application

Best practices